﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using AdoNet = System.Data;
using System.Runtime.CompilerServices;

namespace DataSet4Com
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComDefaultInterface(typeof(IDataColumnList))]
    [Guid("146791B7-196C-47AF-B421-15D202938064")]
    public class DataColumnList : IDataColumnList
    {
        private List<DataColumn> _list;

        public DataColumnList() : this(null) { }

        public DataColumnList(DataColumn[] array)
        {
            _list = new List<DataColumn>();

            if (array != null)
                _list.AddRange(array);
        }

        [ComVisible(false)]
        public List<DataColumn> InternalList
        {
            get { return _list; }
        }

        [DispId(-4)]
        public IEnumerator GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        [DispId(0)]
        [IndexerName("_Default")]
        public DataColumn this[int index]
        {
            get
            {
                return _list[index];
            }
        }
        
        public void Add(DataColumn column)
        {
            _list.Add(column);
        }
        
        public void Clear()
        {
            _list.Clear();
        }

        public bool Contains(DataColumn column)
        {
            return _list.Contains(column);
        }

        public int IndexOf(DataColumn column)
        {
            return _list.IndexOf(column);
        }

        public void Remove(DataColumn column)
        {
            _list.Remove(column);
        }

        public void RemoveAt(int index)
        {
            _list.RemoveAt(index);
        }

        public int Count
        {
            get { return _list.Count; }
        }
    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [Guid("465A2FFA-7A05-4E0F-A396-E5256DBA5143")]
    public interface IDataColumnList
    {
        [DispId(-4)]
        IEnumerator GetEnumerator();

        [DispId(0)]
        [IndexerName("_Default")]
        DataColumn this[int index]
        {
            get;
        }

        void Add(DataColumn column);               

        void Clear();

        bool Contains(DataColumn column);

        int IndexOf(DataColumn column);

        void Remove(DataColumn column);
        
        void RemoveAt(int index);

        int Count
        {
            get;
        }
    }
}
